import React, { Component } from 'react';

class IfComm extends Component {
    state = { 
        num: 1,
    } 
    render() { 
        return (
            <div>
                <h3>当前等级{ this.state.num }</h3>
                {this.showClass()}
                <button onClick={ ()=>{
                    this.add()
                    if(this.state.num == 7){
                        this.setState({num: this.state.num = 1})
                    }
                } }>ADD</button>
            </div>
        );
    }
    add = ()=>{
        this.setState({num: this.state.num + 1})
    }
    showClass = ()=>{
        let sum = this.state.num
        if (sum == 1) return <h2>黑铁</h2>
        if (sum == 2) return <h2>白银</h2>
        if (sum == 3) return <h2>黄金</h2>
        if (sum == 4) return <h2>铂金</h2>
        if (sum == 5) return <h2>星耀</h2>
        if (sum == 6) return <h2>王者</h2>
        if (sum == 7) return <h2>荣耀</h2>
    }
}

export default IfComm;